package com.mktech.taraservice.http.respondHandler;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;

import com.mktech.taralib.entity.LanguageContenVo;
import com.mktech.taraservice.util.JacksonUtil;
import com.mktech.taraservice.util.LogTool;


public class LanguageContentRespondHandler extends BaseRespondHandler<List<LanguageContenVo>>
{
	String TAG = LanguageContentRespondHandler.class.getSimpleName();
	@Override
	protected void onSuccess(String data)
	{
		// TODO Auto-generated method stub
		LogTool.i("onSuccess----data = "+data);
		try
		{
			mResult = new ArrayList<LanguageContenVo>();
			List<LinkedHashMap<String, Object>> list = JacksonUtil.obtain().getObjectMapper().readValue(data, List.class);
			for(Iterator iterator = list.iterator(); iterator.hasNext();)
			{
				LanguageContenVo item = new LanguageContenVo();
				HashMap<String, Object> map = (HashMap<String, Object>) iterator.next();
				Set<String> keySet = map.keySet();
				for(Iterator<String> i = keySet.iterator(); i.hasNext();)
				{
					String key = i.next();
					if(key.equals("ID"))
					{
						item.setID((String) map.get(key));
					}
					else if(key.equals("Title"))
					{
						item.setTitle((String) map.get(key));
					}
					else if(key.equals("Description"))
					{
						item.setDescription((String) map.get(key));
					}
					else if(key.equals("Code"))
					{
						item.setCode((String) map.get(key));
					}
					else if(key.equals("Country"))
					{
						item.setCountry((String) map.get(key));
					}
					else if(key.equals("ImageUrl"))
					{
						item.setImageUrl((String) map.get(key));
					}
					else if(key.equals("TStamp"))
					{
						item.setTStamp((String) map.get(key));
					}
					LogTool.i("key:"+key+"\tvalue:"+map.get(key));
				}
				mResult.add(item);
			}
		}
		catch (JsonParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (JsonMappingException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	protected void onFailure(Throwable throwable)
	{
		// TODO Auto-generated method stub
		LogTool.i("onFailure---- throwable= "+throwable);
	}

}
